<template>
      <el-container>
  <el-header>
      <el-image :src="require('../assets/1.png')" style="margin-left: 60px; height: 60px; width: 70px;">
      
      </el-image>

      <h1 style="margin-left: 150px;margin-top: -50px;width: 300px;height: 10px;">您好，欢迎登录~~~</h1>

                  <i class="el-icon-s-comment"  style="margin-left: 71%;">
                      <el-link type="info" style="margin-left: 5px;margin-top:-3px;">登录页面，调查问卷</el-link>
                  </i>
                  


  </el-header>
  <el-header style="background-color: #fff8f0;height: 40px;">
      
      <i class="el-icon-warning-outline"  style="margin-left: 300px;margin-top: 15px;">依据《网络安全法》，为保障您的账户安全和正常使用，请尽快完成手机号验证！将更有利于保护您的个人隐私。</i>
  </el-header>
    <img class="photo" src="../assets/4.jpg" width="100%" height="100%" alt="" />
    <el-row type="flex" class="row-bg" justify="center">
        
        <el-col :xl="6" :lg="7">
    
            <div class="login-form">
 
             <el-image :src="require('../assets/2.png')" style="height: 250px; width: 290px;margin-top: 50px"></el-image>
            </div>
        </el-col>
        <el-col :span="1" >
            <el-divider direction="vertical" ></el-divider>
        </el-col>
        <el-col :xl="6" :lg="7">
            <el-form  class="right" label-position="right" :rules="rules" label-width="80px," :model="loginForm" ref="loginForm" >
                <el-form-item label="用户名" prop="username" style="width: 380px;margin-top: 132px">
                    <el-input v-model="loginForm.username"></el-input>
                </el-form-item>
                <el-form-item label="密码" prop="password" style="width: 380px;">
                    <el-input type="password" v-model="loginForm.password"></el-input>
                </el-form-item>
                <el-form-item label="验证码" prop="code" style="width: 380px;">
                    <el-input v-model="loginForm.code" style="width: 172px; float: left;" maxlength="5"></el-input>
                    <el-image :src="captchaImg" class="captchaImg"  @click="getCaptcha"></el-image>
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="submitForm('loginForm')">登录</el-button>
                    <el-button @click="resetForm">重置</el-button>
                </el-form-item>
            </el-form>
        </el-col>
    </el-row>
<el-footer> <div>
  <el-link  target="_blank" style="margin-left:35%;">关于我们</el-link>
   <el-link  target="_blank" style="margin-left:40px; ">联系我们</el-link>
 <el-link  target="_blank" style="margin-left:40px; ">人才招聘</el-link>
     <el-link  target="_blank" style="margin-left:40px; ">商家入驻</el-link>
 <el-link  target="_blank" style="margin-left:40px; ">广告服务</el-link>

</div>
    
    
    <span style="margin-left: 40%;"> Copyright © 2004-2021  B Poa.com版权所有</span></el-footer>


    </el-container>

</template>
<script>
   import qs from 'qs'
export default {
    name: "Login",
    data() {
        return {
            loginForm: {
                username: 'admin',
                password: '111111',
                code: 's5q71',
                token: '',
            },
            rules: {
                username: [
                    {required: true, message: '请输入用户名', trigger: 'blur'}
                ],
                password: [
                    {required: true, message: '请输入密码', trigger: 'blur'}
                ],
                code: [
                    {required: true, message: '请输入验证码', trigger: 'blur'},
                    {
                        min: 5,
                        max: 5,
                        message: '验证码为5个字符',
                        trigger: 'blur'
                    }
                ],
            },
         captchaImg: 11111

        };
    }, methods: {
        submitForm(formName) {
            this.$refs[formName].validate((valid) => {
                if (valid) {
                   this.$axios.post('/login',this.loginForm).then( res =>{
                       const jwt = res.headers['authorization']

                       this.$store.commit('SET_TOKEN',jwt)

                       this.$router.push('/index')
                   })


                } else {

                    console.log('error submit!!');
                    return false;
                }
            });
        },
        resetForm(formName) {
            this.$refs[formName].resetFields();
        },
      getCaptcha(){
          this.$axios.get('/captcha').then( res =>{

              console.log("/captcha")
              console.log(res)

              this.loginForm.token = res.data.data.token
          this.captchaImg = res.data.data.captchaImg
      })

        //Result - code.msg
      }

        },
    created(){
        this.getCaptcha()
    }
}

</script>

<style scoped>  

    .el-col {
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100%;
    text-align: center;

}

.el-row {
    height: 100%;
    
    display: flex;
    align-items: center;
    text-align: center;
    height: 580px;
    z-index: 1;
}



.el-divider {
    height: 200px;
    margin-top: 90px;

}


.captchaImg {
    float: left;
    margin-left: 8px;
    border-radius: 4px;


}
.photo{
    position: absolute;
    height: 100%;
    width: 100%;
    z-index: -1;

}

</style>
